//-------------------------------------------------------------------
//	Copyright (c) 2012-2014 Zhirnov Andrey
//	This file is part of the "UXGEN-ES" project.
//	See copyright notice in "Engine.h".
//-------------------------------------------------------------------

#pragma once

#include "Base/Include/BaseObject.h"

namespace Engine
{
namespace Base
{

	namespace EResource
	{
		enum type
		{
			UNKNOWN		= 0,
			AUDIO		= 0x10000000,
			GRAPHICS	= 0x20000000,
		};
	};
	
		
	SHARED_POINTER( Resource );



	//
	// Resource
	//

	class Resource : public BaseObject
	{
	// types
	public:

		//
		// Resource Load Parameters
		//
		struct ResLoadParams
		{
		// types
		public:
			typedef CompileTime::TSignature8<' '>::value_t	signature_t;

		// variables
		private:
			const signature_t	_signature;

		// methods
		public:
			explicit
			ResLoadParams (signature_t signature) : _signature(signature) {}

			template <typename T>
			inline bool			Is () const
			{
				return T::Signature() == _signature;
			}

			template <typename T>
			inline T const &	To () const
			{
				ASSERT( Is<T>() );
				return * (T *) this;
			}
		};


	// variables
	private:
		const EResource::type	_resType;

	protected:
		usize					_memSize;	// size of dynamic allocated data for this resource (RAM or/and VRAM) in bytes


	// methods
	public:
		Resource (EResource::type resType, const EngineSubSystemsRef ess) :
			BaseObject(ess), _resType(resType), _memSize(0)
		{}

		~Resource ()
		{}


		virtual bool SwapData (const ResourcePtr &res)
		{
			CHECK_ERR( res.IsNotNull() and GetType() == res->GetType() );

			_swap( this->_memSize, res->_memSize );
			return true;
		}


		virtual bool IsLoadedWithParams (const ResLoadParams &params) const
		{
			return true;
		}

		virtual bool	IsValid ()		const = 0; //	{ return false; }


		EResource::type	GetType ()		const	{ return _resType; }

		usize			GetMemSize ()	const	{ return _memSize; }
	};

}	// Base
}	// Engine